package com.zkthink.ceres.product.controller;

import com.zkthink.ceres.product.entity.ProductGroup;
import com.zkthink.ceres.product.dto.ProductGroupSaveDTO;
import com.zkthink.ceres.product.dto.ProductGroupUpdateDTO;
import com.zkthink.ceres.product.dto.ProductGroupPageDTO;
import com.zkthink.ceres.product.service.ProductGroupService;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.zkthink.base.controller.SuperController;
import com.zkthink.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.zkthink.security.annotation.PreAuth;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 商品分组表
 * </p>
 *
 * @author JustArgo
 * @date 2020-05-07
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/productGroup")
@Api(value = "ProductGroup", tags = "商品分组表")
//@PreAuth(replace = "productGroup:")
public class ProductGroupController extends SuperController<ProductGroupService, Long, ProductGroup, ProductGroupPageDTO, ProductGroupSaveDTO, ProductGroupUpdateDTO> {

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ProductGroup> productGroupList = list.stream().map((map) -> {
            ProductGroup productGroup = ProductGroup.builder().build();
            //TODO 请在这里完成转换
            return productGroup;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(productGroupList));
    }

    @ApiOperation("删除商品分组")
    @PostMapping("/delProductCategory")
    public R<Boolean> deleteProductGroup(@RequestBody ProductGroupUpdateDTO productGroupUpdateDTO){
        return baseService.deleteProductGroup(productGroupUpdateDTO);
    }
}
